package chapter9.interfaces.interfaceprocessor;
import static utility.Print.*;

public class SwapProcessor implements Processor{

	public String name() {
		return getClass().getSimpleName();
    }

	public Object process(Object input) {
		//we expect a string
		String s = (String) input;
		StringBuilder newString = new StringBuilder();
		
		for (int i = 0; i < (s.length() - 1); i++) {
			newString.append(s.charAt(i + 1));
			newString.append(s.charAt(i));
			i++;
		}
		
		if (s.length() % 2 != 0)
			newString.append(s.charAt(s.length() -1));
		
		print("Result is " + s);
		
		return newString.toString();
    }

}
